package approve.action;

import model.pojo.Document;
import model.pojo.Employee;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.TextView;

public class Re_ViewForm16 extends Activity {
	TextView la_title, la_description, la_content;
	// component
	EditText title, description;
	WebView  currentWeek, nextWeek;
	TextView la_createDate,la_writer,re_createDate;
	EditText re_employee;
	// bundle
	Document doc = null;
	String database = "admin";
	String lang = "EN";
	Bundle language = null;
	Employee emp = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.re_viewform16);
		getComponent();

		loadBundle();
		loadLanguage();

		viewDocument();

	}

	private void getComponent() {
		la_createDate=(TextView) findViewById(R.id.la_createDate);
		la_writer=(TextView) findViewById(R.id.la_writer);
		re_createDate = (TextView) findViewById(R.id.re_createDate);
		re_employee = (EditText) findViewById(R.id.re_employee);
		
		la_title = (TextView) findViewById(R.id.la_title);
		la_description = (TextView) findViewById(R.id.la_description);
		la_content = (TextView) findViewById(R.id.la_content);

		title = (EditText) findViewById(R.id.weekly_title);
		description = (EditText) findViewById(R.id.weekly_description);
		currentWeek = (WebView) findViewById(R.id.currentWeek);
		nextWeek = (WebView) findViewById(R.id.nextWeek);

	}

	private void loadBundle() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
			lang = extras.getString("lang");
			emp = (Employee) extras.get("em");
			doc = (Document) extras.get("doc");
			language = extras.getBundle(lang);
		}
	}

	private void loadLanguage() {
		if (language != null) {
			la_createDate.setText(language.getString("created-date")+": ");
			la_writer.setText(language.getString("writer")+"/"+language.getString("Department"));
			
			la_title.setText(language.getString("title"));
			la_description.setText(language.getString("Description"));
			la_content.setText(language.getString("content"));
		}
	}

	private void viewDocument() {
		if (doc != null) {
			re_createDate.setText(doc.getTimecreate()+"");
			re_employee.setText(doc.getEmployeeName()+"/"+doc.getDepartment());
			
			title.setText(doc.getTitle());

			description.setText(doc.getDescription());

			final String mimeType = "text/html";
			String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
			
			currentWeek.loadData(header + doc.getContent(), mimeType, null);
			
			nextWeek.loadData(header + doc.getContent2(), mimeType, null);

			// System.out.println("contentd: " + contentHtml.getHTML());
		}
	}

}
